package com.vanguard.controller;

import com.github.abel533.echarts.Option;
import com.vanguard.commons.base.BaseController;
import com.vanguard.commons.echarts.OptionData;
import com.vanguard.commons.exception.BusinessException;
import com.vanguard.commons.response.CommonReturnCode;
import com.vanguard.commons.response.HttpResult;
import com.vanguard.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Title: 商品前端控制器
 * @Description:
 * @Author: vanguard
 * @Version: 1.0
 * @Date: 2019/03/11
 */
@RestController
@RequestMapping("/product")
public class ProductController extends BaseController {

    @Autowired
    private ProductService productService;


    /**
     * 组装饼状图数据
     * @param
     * @return
     * @author
     * @date
     */
    @GetMapping("/productType")
    public HttpResult productType() {
        OptionData option = null;
        try {
            option = productService.selectProductType();
            return new HttpResult(CommonReturnCode.OK, option);
        } catch (BusinessException e) {
            return new HttpResult(e.getCode(), e.getMessage());
        }
    }

    /**
     * 组装折线图和柱状图数据
     * @return
     */
    @GetMapping("/productTypeBar")
    public HttpResult productTypeBar() {
        OptionData option = null;
        try {
            option = productService.selectProductTypeBar();
            return new HttpResult(CommonReturnCode.OK, option);
        } catch (BusinessException e) {
            return new HttpResult(e.getCode(), e.getMessage());
        }
    }


}
